package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entry.employee;
import service.service;

/**
 * Servlet implementation class RegisterServlet
 */
public class RegisterServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegisterServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		
		
		String employeename = request.getParameter("employeename");
		String accountname = request.getParameter("accountname");
		String password = request.getParameter("password");
		String phone = request.getParameter("phone");
		String email = request.getParameter("email");
		String[] strdeptid = request.getParameterValues("deptid");
		int deptid = Integer.parseInt(strdeptid[0]);
		
		employee emp = new employee();
		emp.setEmployeename(employeename);
		emp.setUsername(accountname);
		emp.setPassword(password);
		emp.setPhone(phone);
		emp.setEmail(email);
		emp.setDepartmentid(deptid);
		
		service registerservlet = new service(); 
		registerservlet.register(emp);
		
		request.getRequestDispatcher("approveacount.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
